from __future__ import annotations

import argparse
import os

import uvicorn

from .app import create_app


def build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(description="Run the Agent Workspace web server")
    parser.add_argument("--host", default=os.getenv("AW_WEB_HOST", "127.0.0.1"))
    parser.add_argument("--port", type=int, default=int(os.getenv("AW_WEB_PORT", "8000")))
    parser.add_argument("--reload", action="store_true", help="Enable auto-reload (dev only)")
    return parser


def main(argv: list[str] | None = None) -> None:
    parser = build_parser()
    args = parser.parse_args(argv)
    app = create_app()
    uvicorn.run(app, host=args.host, port=args.port, reload=args.reload)


if __name__ == "__main__":
    main()
